package com.dayatang.exam.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.dayatang.domain.ValueObject;

/**
 * 考生相关信息
 * @author yang
 *
 */
@Embeddable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ExamStudentInfo implements ValueObject {
	
	private static final long serialVersionUID = 711299615287375291L;

	/**
	 * �?��考试
	 */
	@org.hibernate.annotations.Parent
	@Column(nullable = false)
	private Exam exam;

	/**
	 * 考生
	 */
	@ManyToOne
	@JoinColumn(name = "USER_ID", nullable = false)
	private User user;

	/**
	 * 报名或参加日�?
	 */
	@Temporal(TemporalType.DATE)
	private Date joinDate;

	public ExamStudentInfo() {
	}

	public ExamStudentInfo(User user, Date joinDate) {
		this.user = user;
		this.joinDate = joinDate;
	}
	
	public ExamStudentInfo(Exam exam, User user) {
		super();
		this.exam = exam;
		this.user = user;
	}

	public Exam getExam() {
		return exam;
	}

	public void setExam(Exam exam) {
		this.exam = exam;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Date getJoinDate() {
		return joinDate;
	}

	public void setJoinDate(Date joinDate) {
		this.joinDate = joinDate;
	}

	@Override
	public boolean equals(final Object other) {
		if (other == null) {
			return false;
		}
		if (!(other instanceof ExamStudentInfo))
			return false;
		ExamStudentInfo castOther = (ExamStudentInfo) other;
		return new EqualsBuilder().append(exam, castOther.exam).append(user, castOther.user).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(exam).append(user).toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("exam", exam).append("user", user).toString();
	}
}
